import { Body, Controller, Get, Post, Query, UseFilters } from "@nestjs/common";
import { PermissionService } from "./permission.service";
import { Permission } from "./entities/permission.entity";
import { HttpExceptionFilter } from "src/exception/http-exception.filter";
import { wrapperResponse } from "src/utils";

@Controller('/permission') // 设置路由前缀为 /users
export class PermissionController {
    constructor(
        private readonly PermissionService:PermissionService
    ){}

    @Get('/detail')
    @UseFilters(new HttpExceptionFilter)
    getDetail(@Query() { id }):Promise<Permission | null> {
        return wrapperResponse(
            this.PermissionService.findOne(id),
            '获取权限详情成功'
        )
    }

    @Get('/list')
    @UseFilters(new HttpExceptionFilter)
    getAllPermission(@Query() query):Promise<Permission[]> {
        return wrapperResponse(
            this.PermissionService.findAll(query),
            '查询权限成功'
        )
    }
    @Post('/create')
    @UseFilters(new HttpExceptionFilter)
    createPermission(@Body() body) {
        return wrapperResponse(
            this.PermissionService.create(body),
            '创建权限成功'
        )
    }

    @Post('/update')
    @UseFilters(new HttpExceptionFilter)
    update(@Body() body) {
        return wrapperResponse(
            this.PermissionService.update(body),
            '更新权限成功'
        )
    }
    @Post('/del')
    @UseFilters(new HttpExceptionFilter)
    delete(@Body() body:{id:string}) {
        return wrapperResponse(
            this.PermissionService.delete(body.id),
            '删除权限成功'
        )
    } 

    @Post('/getListByRoleName')
    @UseFilters(new HttpExceptionFilter)
    getListByRoleName(@Body() body):Promise<Permission | null> {
        return wrapperResponse(
            this.PermissionService.getListByRoleName(body),
            '获取角色匹配的操作权限成功'
        )
    }


}